<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript">
    /*$(document).ready(function() {
        $('#example').dataTable({
            "sPaginationType": "full_numbers"
        });
    });*/
</script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">职等设置 - ${grade == null ? "添加" : "修改"}</h1>

<div class="container_12 clearfix leading">

    <s:if test="#request.grade != null and #request.grade.id != null and #request.grade.duty != null">
        <s:set name="default_duty_id" value="#request.grade.duty.id" scope="page"/>
    </s:if>
    <%@ include file="/WEB-INF/pages/common/common_tree.jsp" %>

    <div class="side grid_8 leading">
        <form class="form has-validation" id="post_form" name="post_form">
            <div class="clear"></div>
            <div class="clearfix">
                <label for="duty_sel" class="form-label">职务 <em>*</em></label>
                <div class="form-input">
                    <select name="grade.duty.id" id="duty_sel"> </select>
                </div>
            </div>

            <div class="clearfix">
                <label for="gradeName" class="form-label">职等名称 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="gradeName" name="grade.gradeName" value="${grade.gradeName}" required="required" placeholder="请输入职等名称"/>
                </div>
            </div>

            <div class="clearfix">
                <label for="gradeSort" class="form-label">职级 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="gradeSort" name="grade.gradeSort" value="${grade.gradeSort}" required="required" placeholder="请输入职级"/>
                </div>
            </div>

            <div class="clearfix">
                <label for="gradePay" class="form-label">基本工资</label>
                <div class="form-input">
                    <input type="text" id="gradePay" name="grade.gradePay" value="${grade.gradePay}" required="required" placeholder="请输入职等工资"/>
                </div>

                <label for="gradePay" class="form-label">职务绩效奖金</label>
                <div class="form-input">
                    <input type="text" id="performance" name="grade.performance" value="${grade.performance}" required="required" placeholder="请输入职务绩效奖金"/>
                </div>

                <div class="clearfix">
                    <label for="gradeContent" class="form-label">职等描述 <em>*</em></label>
                    <div class="form-input">
                        <textarea name="grade.gradeContent" rows="5" required="required" id="gradeContent" placeholder="请输入职务描述">${grade.gradeContent}</textarea>
                    </div>
                </div>

                <div class="clearfix">
                    <label for="salary_structure_sel" class="form-label">福利方案 <em>*</em></label>
                    <div class="form-input">
                        <select name="grade.salaryStructure.id" id="salary_structure_sel">
                            <option>方案一</option>
                            <option>方案二</option>
                            <option>方案三</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-action clearfix">
                <input type="hidden" value="${grade.id}" name="grade.id"/>
                <button class="button"  type="button" onclick="checkForm()">${grade == null ? "添加" : "修改"}</button>
                <button class="button" type="reset">重置</button>
                <a class="button" href="#rank/grade.xhtml">
                    <span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>

<div class="clear"></div>


<script type="text/javascript" src="${ctx}/js/Tree.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
    function findDuty(organizationId) {
        $.getJSON("${ctx}/ajax/duty-list.xhtml?organizationId=" + organizationId, function(duties) {
            $("#uniform-duty_sel span:first").text("");//清除上次选择的职务
            var selObj = $("#duty_sel");
            selObj.html("");
            if (duties != null && duties.length != 0) {
                $.each(duties, function(i, duty) {
                    if(i == 0){
                        $("#uniform-duty_sel span:first").html(duty.dutyName);//设置本次选择的职务
                    }
                    selObj.append("<option value='" + duty.id + "'>" + duty.dutyName + "</option>")
                });
                //selObj.get(0).selectedIndex = 1;
            }
        });
    }
    function checkForm(){
        if($("#duty_sel option").length == 0){
            alert("该组织结构下没有职务，请先添加职务");
            return;
        }
        if($("#duty_sel").val() == null){
            alert("请选择职务");
            return;
        }

        if(checkNull($("#gradeName").attr("value"))){
            alert("职等名称不为空");
            return false;
        }
        if(checkNull($("#gradeSort").attr("value"))){
            alert("职级不为空");
            return false;
        }
        if(checkNull($("#gradePay").attr("value"))){
            alert("职等工资不为空");
            return false;
        }
        if(isNaN($("#gradePay").attr("value"))){
            alert("职等工资填写不正确");
            return false;
        }
        if(checkNull($("#gradeContent").attr("value"))){
            alert("职等描述不为空");
            return false;
        }
        if($("#salary_structure_sel").val() > 0){

        }else{
            alert("请选择福利方案");
            return false;
        }

        var url = "${ctx}/rank/grade_create.xhtml";
        $.ajax(url, {
            type: "POST",
            data: $("#post_form").serialize(),
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function() {}
        });
    }

    $(function(){
        findSalaryStructureList(null);
    });
    function onTopOrganizationClick(id, obj){
        findSalaryStructureList(id);
    }
    function findSalaryStructureList(topOrganizationId){
        var url = "${ctx}/ajax/salary-structe-find.xhtml";
        $.ajax(url, {
            type: "POST",
            data:{"organizationId":topOrganizationId},
            dataType:"json",
            cache:false,
            success:function(structes) {
                var tempHtml = "";
                if(structes != null && structes.length > 0){
                    for(var i=0; i<structes.length; i++){
                        tempHtml += '<option value="'+structes[i][0]+'">'+structes[i][1]+'</option>'
                    }
                    $("#salary_structure_sel").prev("span").html(structes[0][1]);
                } else {
                    $("#salary_structure_sel").prev("span").html("");
                }
                $("#salary_structure_sel").html(tempHtml);
            },
            complete:function() {}
        });
    }
</script>

    